import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';
import updateButtonStatus from "./updateButtonStatus";
import getMainTableData from "./getMainTableData";
import {getAppPageConfig} from "src/hrpub/common/utils/utils";
export default function getTableHeaderData() {

    const {orgVal, rosterRefVal, json, hasSearched} = this.state;

    if (!orgVal.refpk || !rosterRefVal.refpk) return;
    let postData = {
        pk_org: this.props.isOrg ? orgVal.refpk : '',//组织传值和pk_org_ref一样
        pk_org_ref: orgVal.refpk,
        pk_rpt_def: rosterRefVal.refpk
    };

    return proFetch({
        url: '/nccloud/hrhi/listrep/ListRptSelectRptAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success) {
                let rosterColumns = res.data.tableInfo;
                const {meta} = this.props;
                const tempMeta = meta.getMeta();
                let tableMeta = {
                    "moduletype": "table",
                    "pagination": false,
                    "code": "rosterTable",
                    "name": "员工花名册列表",
                    "oid": "100DZ710000000001HMC",
                    "appcode": getAppPageConfig().appcode,
                    "pagecode": getAppPageConfig().pagecode,
                    items: []
                };
                rosterColumns.forEach(item => tableMeta.items.push(
                    {
                        "hyperlinkflag": false,
                        "islock": false,
                        "istotal": false,
                        "width": "120px",
                        "attrcode": item.key,
                        "color": "#6E6E77",
                        "containlower": false,
                        "datatype": "1",
                        "disabled": true,
                        "editAfterFlag": false,
                        "fieldDisplayed": "refcode",
                        "fieldValued": "refpk",
                        "isDataPowerEnable": true,
                        "isnotmeta": false,
                        "isResLabel": false,
                        "isrevise": false,
                        "isShowUnit": false,
                        "itemtype": "input",
                        "label": item.name,
                        "maxlength": "40",
                        "onlyLeafCanSelect": false,
                        "position": "1",
                        "required": false,
                        "scale": "0",
                        "visible": true
                    }
                ));
                tempMeta.rosterTable = tableMeta;
                meta.setMeta(tempMeta);
                if (hasSearched) {
                    getMainTableData.call(this)
                } else {
                    updateButtonStatus.call(this)
                }
                /*rosterColumns.forEach(item => {
                    item.title = item.name;
                    item.dataIndex = item.key;
                    item.width = '140px';
                });
                rosterColumns.unshift({
                    title: json['hi6007-000282'],
                    dataIndex: 'numberindex',
                    className: 'table-index',
                    visible: true,
                    itemtype: 'customer',
                    width: '60px'
                });
                this.setState({
                    rosterColumns,
                    rosterData: []
                }, () => {
                    if (hasSearched) {
                        getMainTableData.call(this)
                    } else {
                        updateButtonStatus.call(this)
                    }
                })*/
            }
        });
}
